# Mononeurona 2008 GPLv3
# Create your views here.
from django.shortcuts import render_to_response
from django.db import models
from django.core.mail import send_mail
from django.http import Http404
from models import Post
from datetime import datetime
import os, unittest


def latest_posts(request):
    post_list = Post.objects.order_by('date')[:10]
    return render_to_response('blog/view.html', {'post_list':post_list})

def display(request):
    post_list = Post.objects.filter(status=1).order_by("-id")[:10]
    #__newMail()
    return render_to_response('blog/display.html', {'post_list':post_list})

def view(request, offset):
    #exit(raise Exception(repr(offset)))
    post_id = int(offset)
    post = Post.objects.get(id=post_id)
    mydict = {'post':post}
    #exit(raise Exception(repr(post)))
    if  post.comment == 1:
      mydict['f']  = 'forma'
    else:
      mydict['f']  = 'no hay forma'
    
    return render_to_response('blog/view.html', mydict)

def __newMail():
    send_mail('This is the subject', 'Gracias! for subscribing to mononeurona.org alerts', 'support@gmail.com', ['mmontoya@gmail.com'])
    return True

class Feed(models.Model):
    """
    storage for "what's new?" feeds
    """
    site = models.PositiveSmallIntegerField(unique=True) # site id
    html = models.TextField() # rendered html
    rss = models.CharField(max_length=4) # rss
